<?php

namespace app\admin\controller;

use think\facade\Request;
use app\common\Common;
use app\admin\service\UserService;
use app\admin\service\PayComplaintService;

class Proposal extends Base
{
    private $service;
    private $payComplaintService;

    public function __construct(UserService $service, PayComplaintService $payComplaintService)
    {
        parent::__construct();
        $this->service = $service;
        $this->payComplaintService = $payComplaintService;
    }

    // 渲染投诉建议列表页面
    public function index()
    {
        return view();
    }

    // 投诉建议列表
    public function list()
    {
        $params = Request::param();

        $data = $this->service->getUserProposalList($params);

        return Common::success($data);
    }

    // 渲染用户详情页面
    public function info()
    {
        return view();
    }

    /**
     * 投诉建议详情
     * 
     * @author zhixiang0215@126.com
     * @param int id
     * @return json
     */
    public function detail()
    {
        $params = Request::param();

        try {
            validate(\app\admin\validate\User::class)->scene('proposal_detail')->check($params);
        } catch (\Exception $e) {
            return Common::fail($e->getError());
        }

        $data = $this->service->getUserProposalDetail($params['id']);

        return Common::success($data);
    }

    // 渲染第三方支付查询投诉单列表页面
    public function queryIndex()
    {
        return view();
    }

    // 第三方支付查询投诉单列表
    public function queryList()
    {
        $params = Request::param();
        $data = $this->payComplaintService->getComplaintList($params);

        if (!empty($data['message'])) {
            return Common::fail($data['message']);
        }
        return Common::success($data);
    }

    // 渲染回复用户页面
    public function responseUser()
    {
        return view();
    }

    // 回复用户
    public function replyUser()
    {
        $params = Request::param();

        $data = $this->payComplaintService->replyUser($params);

        if (!empty($data['message'])) {
            return Common::fail($data['message']);
        }
        return Common::success();
    }

    // 反馈处理完成
    public function complete()
    {
        $params = Request::param();
        $data = $this->payComplaintService->complete($params);

        if (!empty($data['message'])) {
            return Common::fail($data['message']);
        }
        return Common::success();
    }

    // 更新退款
    public function updateRefund()
    {
        return view();
    }

    // 退款页面
    public function refundShow()
    {
        return view();
    }

    // 更新退款状态
    public function updateRefundStatus()
    {
        $params = Request::param();
        $data = $this->payComplaintService->updateRefundStatus($params);

        if (!empty($data['message'])) {
            return Common::fail($data['message']);
        }
        return Common::success();
    }

    // 退款
    public function refund()
    {
        $params = Request::param();
        $data = $this->payComplaintService->refund($params);

        if (!empty($data['message'])) {
            return Common::fail($data['message']);
        }
        return Common::success();
    }
}